Agentic Browser

Documentation

Agent communication models

Introduction#

This page provides detailed data model documentation for agent communication schemas, focusing on:

  • The GenerateScriptRequest model used for browser automation requests, including goal specification, target URL handling, DOM structure representation, and constraint definitions
  • The corresponding response model and validation rules
  • The agent message payload structure, conversation context management, and state preservation mechanisms
  • Field definitions, optional parameter handling, and data type specifications
  • Examples of request/response cycles, error handling patterns, and validation scenarios
  • The relationship between agent models and the reactive agent system architecture

Project structure#

The agent communication models span three primary layers:

  • Request/response models: Strongly typed Pydantic models defining the shape of incoming/outgoing data
  • Routers: FastAPI endpoints that validate inputs and orchestrate service calls
  • Services: Business logic that interacts with LLMs, sanitizers, and external systems

Core components#

This section documents the two primary agent communication schemas and their relationships.

GenerateScriptRequest model#

Purpose: Defines the input schema for generating a browser automation action plan from a natural language goal.

Fields:

  • goal: Required string describing the automation task
  • target_url: Optional string; defaults to empty string if omitted
  • dom_structure: Optional dictionary; defaults to empty dictionary if omitted
  • constraints: Optional dictionary; defaults to empty dictionary if omitted

Validation and behavior:

  • Goal is mandatory; router rejects requests without it
  • DOM structure and constraints are optional and used to enrich the LLM prompt
  • Router forwards validated fields to the service

Data type specifications:

  • goal: string
  • target_url: string | null
  • dom_structure: dict[str, Any] | null
  • constraints: dict[str, Any] | null

Optional parameter handling:

  • Empty string fallback for target_url
  • Empty dict fallback for dom_structure and constraints

GenerateScriptResponse model#

Purpose: Defines the standardized response for automation plan generation.

Fields:

  • ok: Boolean flag indicating success or failure
  • action_plan: Optional dictionary containing the generated JSON action plan
  • error: Optional string describing the error on failure
  • problems: Optional list of validation problem strings
  • raw_response: Optional string containing the raw LLM output for inspection

Validation and behavior:

  • On success: ok is true and action_plan is populated
  • On validation failure: ok is false, problems is set, error describes the issue
  • On general failure: ok is false, error contains the error message

ReactAgentRequest and ReactAgentResponse models#

Purpose: Define the input and output schemas for the reactive agent system that handles general conversational tasks with optional tool use.

ReactAgentRequest fields:

  • messages: Required list of AgentMessage entries; minimum length 1
  • google_access_token: Optional string; supports multiple aliases for tolerance
  • pyjiit_login_response: Optional nested PyjiitLoginResponse object

AgentMessage fields:

  • role: Literal role among “system”, “user”, “assistant”, “tool”
  • content: Required string with minimum length 1
  • name: Optional string
  • tool_call_id: Optional string; alias supported
  • tool_calls: Optional list of tool call dictionaries

ReactAgentResponse fields:

  • messages: Final conversation state including the agent reply
  • output: Content of the latest assistant message

Validation and behavior:

  • Messages list must not be empty
  • Role must be one of the allowed literals
  • Tool calls are preserved when present
  • Response mirrors the final state of the conversation

Architecture overview#

The agent communication architecture integrates extension-driven payload construction, API validation, service orchestration, and agent/graph execution.

Detailed component analysis#

GenerateScriptRequest/Response workflow#

This workflow demonstrates the end-to-end cycle for generating a browser automation action plan.

React agent message payload and conversation state#

The reactive agent system manages conversation context and preserves state across turns.

DOM structure representation and target URL handling#

The extension captures DOM information and constructs the GenerateScriptRequest payload.

Validation rules and error handling patterns#

Validation spans multiple layers:

  • Router-level validation ensures required fields are present
  • Service-level prompt composition and LLM invocation
  • Sanitizer validates JSON structure and action semantics
  • Error responses maintain a consistent shape

Dependency analysis#

The following diagram shows key dependencies between models, routers, services, and utilities.

Performance considerations#

  • DOM structure truncation: Interactive elements are limited to avoid excessive payload sizes
  • Prompt token limits: DOM summaries cap the number of interactive elements included
  • Caching: The reactive agent graph is cached to reduce compilation overhead
  • Optional fields: Using optional fields reduces unnecessary data transfer and processing

Troubleshooting guide#

Common issues and resolutions:

  • Missing goal: Router returns HTTP 400 with a descriptive message
  • Validation failures: Service returns ok=false with problems list and raw_response for debugging
  • General errors: Service returns ok=false with error message
  • React agent errors: Service logs and returns a generic apology message

Conclusion#

The agent communication models provide a reliable, typed interface for both browser automation and conversational AI tasks. The GenerateScriptRequest model enables precise automation planning by incorporating DOM context and constraints, while the ReactAgentRequest/Response models support rich conversational exchanges with optional tool use. Validation and error handling are consistently applied across layers to ensure predictable behavior and clear feedback.